/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ultrasoft.farmasoft.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

import org.springframework.format.annotation.DateTimeFormat;

/**
 *
 * @author Administrador
 */
@Entity										
@Table(name = "transaction")
@XmlRootElement		// 
@NamedQueries({
    @NamedQuery(name = "Transaction.findAll", query = "SELECT t FROM Transaction t"),
    @NamedQuery(name = "Transaction.findByPackageId", query = "SELECT t FROM Transaction t WHERE t.packageId.packageId = :packageId"),
    @NamedQuery(name = "Transaction.findByPharmacyIdByUserId", query = "SELECT t FROM Transaction t WHERE t.userpharmacy.userpharmacyPK.pharmacyId = :pharmacyId AND t.userpharmacy.userpharmacyPK.userId = :userId"),
    @NamedQuery(name = "Transaction.findByClientId", query = "SELECT t FROM Transaction t WHERE t.clientId.clientId = :clientId"),
    @NamedQuery(name = "Transaction.findByOperationId", query = "SELECT t FROM Transaction t WHERE t.operationId.operationId = :operationId"),
    @NamedQuery(name = "Transaction.findByPeriodIdsByTransactionId", query = "SELECT t FROM Transaction t WHERE t.transactionPK.periodIds = :periodIds AND t.transactionPK.transactionId = :transactionId"),
    @NamedQuery(name = "Transaction.findByPeriodIds", query = "SELECT t FROM Transaction t WHERE t.transactionPK.periodIds = :periodIds"),
    @NamedQuery(name = "Transaction.findByTransactionId", query = "SELECT t FROM Transaction t WHERE t.transactionPK.transactionId = :transactionId"),
    @NamedQuery(name = "Transaction.findByDateTransaction", query = "SELECT t FROM Transaction t WHERE t.dateTransaction = :dateTransaction"),
    @NamedQuery(name = "Transaction.findByDateStartTransactionByEndTransaction", query = "SELECT t FROM Transaction t WHERE t.dateTransaction >= :start AND t.dateTransaction <= :end ORDER BY t.userpharmacy.pharmacy.pharmacyId,t.userpharmacy.user.userId,t.dateTransaction "),
    @NamedQuery(name = "Transaction.findByPharmacyIdByDateStartTransactionByEndTransaction", query = "SELECT t FROM Transaction t WHERE t.userpharmacy.pharmacy.pharmacyId = :pharmacyId AND t.dateTransaction >= :start AND t.dateTransaction <= :end ORDER BY t.userpharmacy.pharmacy.pharmacyId,t.userpharmacy.user.userId,t.dateTransaction "),
    @NamedQuery(name = "Transaction.findByUnits", query = "SELECT t FROM Transaction t WHERE t.units = :units"),
    @NamedQuery(name = "Transaction.findByAmount", query = "SELECT t FROM Transaction t WHERE t.amount = :amount"),
    @NamedQuery(name = "Transaction.findByRemark", query = "SELECT t FROM Transaction t WHERE t.remark = :remark"),
    @NamedQuery(name = "Transaction.findTransactionIdByPeriodIdsMax", query = "SELECT max(t.transactionPK.transactionId) FROM Transaction t WHERE t.transactionPK.periodIds = :periodIds"),
    @NamedQuery(name = "Transaction.findByGroupItems", query = "SELECT t FROM Transaction t WHERE t.groupItems = :groupItems")})
public class Transaction implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected TransactionPK transactionPK;   
   
    @Column(name = "dateTransaction")
    @Temporal(TemporalType.TIMESTAMP)    //@Temporal(TemporalType.DATE)
    private Date dateTransaction;
	@Basic(optional = false)
    @Column(name = "units")
    private short units;
    @Basic(optional = false)
    @Column(name = "amount")
    private float amount;
    @Column(name = "remark")
    private String remark;
    @Column(name = "groupItems")
    private String groupItems;
    @JoinColumns({
        @JoinColumn(name = "pharmacyId", referencedColumnName = "pharmacyId"),
        @JoinColumn(name = "userId", referencedColumnName = "userId")})
    @ManyToOne
    private Userpharmacy userpharmacy;
    @JoinColumn(name = "clientId", referencedColumnName = "clientId")
    @ManyToOne
    private Client clientId;
    @JoinColumn(name = "operationId", referencedColumnName = "operationId")
    @ManyToOne
    private Operation operationId;
    @JoinColumn(name = "acquittanceId", referencedColumnName = "acquittanceId")
    @ManyToOne
    private Acquittance acquittanceId;
    @JoinColumn(name = "packageId", referencedColumnName = "packageId")
    @ManyToOne
    private Package packageId;
    @JoinColumns({
        @JoinColumn(name = "periodId", referencedColumnName = "periodId"),
        @JoinColumn(name = "billId", referencedColumnName = "billId")})
    @ManyToOne
    private Bill bill;
    @JoinColumns({
        @JoinColumn(name = "Use_pharmacyId", referencedColumnName = "pharmacyId"),
        @JoinColumn(name = "Use_userId", referencedColumnName = "userId")})
    @ManyToOne
    private Userpharmacy userpharmacy1;

    public Transaction() {
    }

    public Transaction(TransactionPK transactionPK) {
        this.transactionPK = transactionPK;
    }

    public Transaction(TransactionPK transactionPK, short units, float amount) {
        this.transactionPK = transactionPK;
        this.units = units;
        this.amount = amount;
    }

    public Transaction(int periodIds, int transactionId) {
        this.transactionPK = new TransactionPK(periodIds, transactionId);
    }

    public TransactionPK getTransactionPK() {
        return transactionPK;
    }

    public void setTransactionPK(TransactionPK transactionPK) {
        this.transactionPK = transactionPK;
    }
    
    public Date getDateTransaction() {
		return dateTransaction;
	}

	public void setDateTransaction(Date dateTransaction) {
		this.dateTransaction = dateTransaction;
	}
	
    public short getUnits() {
        return units;
    }

    public void setUnits(short units) {
        this.units = units;
    }

    public float getAmount() {
        return amount;
    }

    public void setAmount(float amount) {
        this.amount = amount;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getGroupItems() {
        return groupItems;
    }

    public void setGroupItems(String groupItems) {
        this.groupItems = groupItems;
    }

    public Userpharmacy getUserpharmacy() {
        return userpharmacy;
    }

    public void setUserpharmacy(Userpharmacy userpharmacy) {
        this.userpharmacy = userpharmacy;
    }

    public Client getClientId() {
        return clientId;
    }

    public void setClientId(Client clientId) {
        this.clientId = clientId;
    }

    public Operation getOperationId() {
        return operationId;
    }

    public void setOperationId(Operation operationId) {
        this.operationId = operationId;
    }

    public Acquittance getAcquittanceId() {
        return acquittanceId;
    }

    public void setAcquittanceId(Acquittance acquittanceId) {
        this.acquittanceId = acquittanceId;
    }

    public Package getPackageId() {
        return packageId;
    }

    public void setPackageId(Package packageId) {
        this.packageId = packageId;
    }

    public Bill getBill() {
        return bill;
    }

    public void setBill(Bill bill) {
        this.bill = bill;
    }

    public Userpharmacy getUserpharmacy1() {
        return userpharmacy1;
    }

    public void setUserpharmacy1(Userpharmacy userpharmacy1) {
        this.userpharmacy1 = userpharmacy1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (transactionPK != null ? transactionPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Transaction)) {
            return false;
        }
        Transaction other = (Transaction) object;
        if ((this.transactionPK == null && other.transactionPK != null) || (this.transactionPK != null && !this.transactionPK.equals(other.transactionPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.ultrasoft.farmasoft.domain.Transaction[ transactionPK=" + transactionPK + " ]";
    }
    
}
